﻿#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#define MAXLINE 80
#define SERVER_PORT 8000

int main(int argc ,char * argv[])
{
	struct sockaddr_in server_addr;
	char buf[MAXLINE];
	int sockfd, n;
	char * str;
	int i = 10;

	if(argc != 2)
	{
		return 0;
	}
	str = argv[1];

	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	bzero(&server_addr, sizeof(server_addr));
	server_addr.sin_family = AF_INET;
	inet_pton(AF_INET, "127.0.0.1", &server_addr.sin_addr);
	server_addr.sin_port = htons(SERVER_PORT);
	connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr));
	while(1)
	{
		write(sockfd, str, strlen(str));
		n = read(sockfd, buf, MAXLINE);
		write(STDOUT_FILENO, buf, n);
		printf("\n");
		sleep(1);
		i--;
	}
	close(sockfd);
	exit(2);
}
